package com.eight.weather.controller;

import com.eight.weather.entity.WeatherEntity;
import com.eight.weather.entity.WeatherEntity;
import com.eight.weather.service.WeatherService;
import com.eight.weather.service.WeatherService;
import org.springframework.web.bind.annotation.*;

//张和积
@RestController
@RequestMapping("/weather")
public class WeatherController {
    private final WeatherService weatherService;

    public WeatherController(WeatherService weatherService) {
        this.weatherService = weatherService;
    }

    // 新增天气信息
    @PostMapping
    public boolean addWeather(@RequestBody WeatherEntity weatherEntity) {
        return weatherService.addWeather(weatherEntity);
    }

    // 删除天气信息
    @DeleteMapping("/{id}")
    public boolean deleteWeather(@PathVariable Long id) {
        return weatherService.deleteWeatherById(id);
    }

    // 修改天气信息
    @PutMapping
    public boolean updateWeather(@RequestBody WeatherEntity weatherEntity) {
        return weatherService.updateWeather(weatherEntity);
    }

    // 查询天气信息
    @GetMapping("/{id}")
    public WeatherEntity getWeather(@PathVariable Long id) {
        return weatherService.getWeatherById(id);
    }
}